import { TBY } from '@/api/config/servicePort'
import http from '@/api'
import { ResPage } from '@/api/interface'

export namespace TbySpeciesCategory {
  export interface Record {
    id: number
    categoryName: string
    parentId: number
    layerCode: string
    useOverview: number
    children: Record[]
  }

  export interface Form {
    id: number
    categoryName: string
    parentId: number
    layerCode: string
    useOverview: number
  }

  export const useOverviewType = [
    { value: 0, label: '禁止' },
    { value: 1, label: '允许' }
  ]
}

// 树型表格数据
export function treeTableList() {
  return http.get<ResPage<TbySpeciesCategory.Record>>(TBY + '/species_category/tree_table_list')
}

// 下拉选
export function optionsSpeciesCategory() {
  return http.get<OptionType[]>(TBY + '/species_category/options')
}

// 物种分类详情
export const getSpeciesCategoryDetail = (id: number) => {
  return http.get<Partial<TbySpeciesCategory.Form>>(TBY + `/species_category/get`, { id }, { loading: false })
}

// 新增或物种分类
export const saveOrUpdateSpeciesCategory = (params: Partial<TbySpeciesCategory.Form>) => {
  return http.post(TBY + `/species_category/save`, params)
}

// 删除物种分类
export const removeSpeciesCategory = (id: number) => {
  return http.delete(TBY + `/species_category/delete`, { id })
}
